import axios from "axios";
import config from "@/config/config.js";
import menuRequest from "@/api/menu.js";

const maintainItemsRequest={
    loadItems(items,page=1,limit=10,callBack){
        let url = config.typeBaseUrl+"/items/list?page="+page+"&limit="+limit;
        if (items){
            if (items.projectCode){
                url += "&projectCode=" +items.projectCode;
            }
            if (items.projectName){
                url += "&projectName=" +items.projectName;
            }
            if (items.projectType){
                url += "&projectType=" +items.projectType;
            }
            axios.get(url).then(res=>{
                callBack(res.data);
            })
        }
    },

    addItems(items,callBack){
        console.log(items)
        let url = config.typeBaseUrl + "/items/add";
        axios.put(url,items).then(res=>{
            callBack(res.data);
        })
    },

    updateItems(items,callBack){
        let url = config.typeBaseUrl + "/items/updateItems"
        axios.put(url,items).then(res=>{
            callBack(res.data);
        })
    },

    selectById(projectId,callBack){
        let url = config.typeBaseUrl + "/items/selectById?projectId=" +projectId
        axios.get(url).then(res=>{
            callBack(res.data);
        })
    },

    deleteItem(projectId,callBack){
        let url = config.typeBaseUrl + "/items/updateStatus?projectId=" +projectId
        axios.put(url).then(res=>{
            callBack(res.data)
        })
    }

}
export default maintainItemsRequest;